import Mock from 'mockjs'

// const BASE_URL = '/RCIM/information'
const BASE_URL = '/Cockpit.asmx'

const List = []
const count = 100

const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

for (let i = 0; i < count; i++) {
	List.push(Mock.mock({
		id: '@increment',
		timestamp: +Mock.Random.date('T'),
		author: '@first',
		reviewer: '@first',
		title: '@title(5, 10)',
		content_short: 'mock data',
		content: baseContent,
		forecast: '@float(0, 100, 2, 2)',
		importance: '@integer(1, 3)',
		'type|1': ['CN', 'US', 'JP', 'EU'],
		'status|1': ['published', 'draft', 'deleted'],
		display_time: '@datetime',
		comment_disabled: true,
		pageviews: '@integer(300, 5000)',
		image_uri,
		platforms: ['a-platform']
	}))
}

export default [{
		url: `${BASE_URL}/abnormalAndWork1`,
		type: 'post',
		response: config => {
			const {
				importance,
				type,
				title,
				page = 1,
				limit = 20,
				sort
			} = config.query

			let mockList = List.filter(item => {
				if (importance && item.importance !== +importance) return false
				if (type && item.type !== type) return false
				if (title && item.title.indexOf(title) < 0) return false
				return true
			})

			if (sort === '-id') {
				mockList = mockList.reverse()
			}

			const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

			return {
				code: 200,
				data: {
					value: '我进行一下测试，看看数据',
					data: pageList,
				}
			}
		}
	},
	// 月度异常趋势（陆云）
	{
		url: `${BASE_URL}/abnormalTrend`,
		type: 'post',
		response: config => {
			const {
				userId,
				startTime,
				endTime
			} = config.query

			// let mockList = List.filter(item => {
			//     if (importance && item.importance !== +importance) return false
			//     if (type && item.type !== type) return false
			//     if (title && item.title.indexOf(title) < 0) return false
			//     return true
			// })

			// if (sort === '-id') {
			//     mockList = mockList.reverse()
			// }

			// const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
			let dataList = [];
			for (let i = 0; i < 6; i++) {
				dataList.push(Mock.mock({
					'month|+1': 6 + i,
					'value|1-30': 100
				}))
			}
			return {
				code: 200,
				data: {
					value: '我进行一下测试，看看数据',
					trendData: dataList
				}
			}
		}
	},
	// 区域异常情况（陆云）
	{
		url: `${BASE_URL}/regionalAnomaly`,
		type: 'post',
		response: config => {
			const {
				userId
			} = config.query

			let dataList = [];
			for (let i = 0; i < 6; i++) {
				dataList.push(Mock.mock({
					'value|1-10': 3,
					legendname: "项目" + (i + 1),
					name: "项目" + i + 1,
					itemStyle: {
						'color|1': ["#fca223", '#921140', '#bb0505', '#fc2a2a', '#fca223']
					}
				}))
			}
			let abnormalTotal = 0
			dataList.forEach(item => {
				abnormalTotal += item.value
			})
			return {
				code: 200,
				data: {
					value: '我进行一下测试，看看数据',
					data: {
						seriesData: dataList,
						abnormalTotal
					},
				}
			}
		}
	},
	// 督办信息（陆云）
	{
		url: `${BASE_URL}/supervisoryInfo`,
		type: 'post',
		response: config => {
			const {
				userId
			} = config.query

			let dataList = [];
			for (let i = 0; i < 3; i++) {
				dataList.push(Mock.mock({
					'enterprise|1': ["中国石油", "中国石化", "中国海油"],
					sourceCode: "03123311",
					nuclideName: "核素名称",
					abnormalType: "异常类型",
					happenTime: "2019-12-33 12:12:12"
				}))
			}
			return {
				code: 200,
				data: {
					value: '我进行一下测试，看看数据',
					supervisoryArray: dataList,
					abnormalTotal: dataList.length
				}
			}
		}
	},
	// 行业top5（陆云）
	{
		url: `${BASE_URL}/classificationIndustry`,
		type: 'post',
		response: config => {
			const {
				userId,
				typeId
			} = config.query

			let dataList = [];
			// for (let i = 0; i < 5; i++) {
			//     dataList.push(Mock.mock(
			//         { 'name|1': ["科研用源","测厚仪","探伤机","医用源","XXX源"],
			//         'number|1-100': 100,
			//         'color|1': ["#4a90e2","#50e3c2","#ff9b53","#d03702","#e1da83"]
			//     }
			//     ))
			// }
			let data = Mock.mock({
				"dataList|5": [{
					'name|1': ["科研用源", "测厚仪", "探伤机", "医用源", "XXX源"],
					value: "@natural(1,100)",
					percent: "",
					color: "@hex"
				}]
			})
			data.dataList = data.dataList.map(v => {
				const total = data.dataList.reduce((prev, next) => prev + next.value, 0)
				v.percent = parseFloat(v.value / total).toFixed(2) * 100
				return v
			})
			data.dataList.sort((a, b) => b.value - a.value)
			return {
				code: 200,
				data: {
					value: '我进行一下测试，看看数据',
					data: {
						dataList: data.dataList
					},
				}
			}
		}
	},
	// 核安全排名top5（陆云）
	{
		url: `${BASE_URL}/nuclearSafety`,
		type: 'post',
		response: config => {
			const {
				userId
			} = config.query

			let dataList = [];
			for (let i = 0; i < 5; i++) {
				dataList.push(Mock.mock({
					'name|1': ["医用源1", "医用源2", "医用源3", "医用源4", "医用源1"],
					'number|1-100': 100
				}))
			}
			return {
				code: 200,
				data: {
					value: '我进行一下测试，看看数据',
					data: {
						safetyList: dataList
					},
				}
			}
		}
	},
	// 异常和作业（陆云）
	{
		url: `${BASE_URL}/abnormalAndWork`,
		type: 'post',
		response: config => {
			const {
				userId
			} = config.query
			const data = Mock.mock({
				abnormalNum: 10, // 异常总数
				handleAbnormalNum: 2, // 未处理
				noHandleAbnormaNum: 8, // 未处理
				'libraryNum|1-10': 2, // 在库
				'transportNum|1-10': 9, // 运输
				'workNum|1-10': 3, // 作业
			})
			return {
				code: 200,
				data: {
					value: '我进行一下测试，看看数据',
					data: {
						abnormalAndWork: data
					},
				}
			}
		}
	},
	/**
	 * qiuliang 地图点位获取
	 */
	{
		url: `${BASE_URL}/mapData`,
		type: 'post',
		response: config => {
			// const geoCoordMap = {
			// 	"蓝创公司": [120.281254, 31.472469],
			// 	"江苏医药学院": [120.177884, 33.332416],
			// 	"一辆汽车": [120.544393, 31.75392]
			// }
			let mapData = {
				enterprise: [
					{
						name: "@cname",
						iconType: "enterprise",
						lat: '31.472469',
						lng: '120.281254',
					}
				],
				site: [
					{
						name: "@cname",
						iconType: "site",
						lat: '33.332416',
						lng: '120.177884',
					}
				],	
				car: [
					{
						name: "@cname",
						iconType: "car",
						lat: '31.75392',
						lng: '120.544393',
					}
					],	
				
				sourceMove: [
					{
						name: "@cname",
						iconType: "sourceMove",
						lat: '32.09318',
						lng: '118.802682',
					}
				]
			}
			// for (const key in geoCoordMap) {
			// 	mapData.push({
			// 		name: key,
			// 		"iconType|1": ["company", "car", "person"],
			// 		value: "@integer(1, 100)",
			// 		"country|1": ["无锡", "盐城", "苏州"]
			// 	})
			// }
			mapData = Mock.mock(mapData)
			return {
				code: 200,
				data: {
					value: '看看数据',
					data: mapData,
				}
			}
		}
	},
	/**
	 * qiuliang 地图上的总数
	 */
	{
		url: `${BASE_URL}/information/getCount`,
		type: 'post',
		response: config => {
			let data = Mock.mock({
				"countData|3": [{
					name: "@cword(1)总数",
					count: "@integer(1, 1000)"
				}]
			})
			return {
				code: 200,
				msg: '',
				data: data
			}
		}
	},
	/**
	 * qiuliang 企业分布总数
	 */
	{
		url: `${BASE_URL}/enterpriseDistribution`,
		type: 'post',
		response: config => {
			const data = Mock.mock({
				"companyData|7": [{
					area: "@city",
					number: "@integer(1, 100)"
				}]
			})
			return {
				code: 200,
				msg: '',
				data: data
			}
		}
	},
	/**
	 * qiuliang 移动源/固定源
	 */
	{
		url: `${BASE_URL}/getSourceData`,
		type: 'post',
		response: config => {
			const {
				type
			} = config.query
			console.log(type);

			let data = []
			const stationData = Mock.mock({
				"tableData|10": [{
					id: "@guid",
					enterprise: "@ctitle",
					place: "@city(true)",
					installPlace: "@city(true)",
					"applicationType|1": ["一应用", "二应用"],
					dose: "@natural(1,10)",
					colletTime: "@date"
				}]

			})
			const moveData = Mock.mock({
				"tableData|10": [{
					id: "@guid",
					enterprise: "@ctitle",
					area: "@city(true)",
					"applicationType|1": ["好的应用", "耨应用"],
					installPlace: "@city(true)",
					dose: "@natural(1,10)",
					"battery|1": ["100%", "90%", "80%", "50%", "20%"],
					"status|1": ["正常", "异常"],
					colletTime: "@date"
				}]
			})
			data = Number(type) ? stationData : moveData
			return {
				code: 200,
				msg: '',
				data: data
			}
		}
	},
	/**
	 * qiuliang 源危险等级分布
	 */
	{
		url: `${BASE_URL}/information/sourceHazardLevel`,
		type: 'post',
		response: config => {
			const defList = [{
					name: "Ⅰ类",
					itemStyle: {
						color: "#d0021b"
					}
				},
				{
					name: "Ⅱ类",
					itemStyle: {
						color: "#ff4747"
					}
				}, {
					name: "Ⅲ类",
					itemStyle: {
						color: "#f8780e"
					}
				},
				{
					name: "Ⅳ类",
					itemStyle: {
						color: "#fac14b"
					}
				},
				{
					name: "Ⅴ类",
					itemStyle: {
						color: "#fff29a"
					}
				}
			]

			const list = defList.map(v => {
				v.id = "@guid"
				v.value = "@natural(1,100)"
				return v
			})
			const data = {
				levelList: Mock.mock(list)
			}
			return {
				code: 200,
				msg: '',
				data: data
			}
		}
	},
	/**
	 * 源总数，源危险等级分布，行业top5，核安全top5
	 */
	{
		url: `${BASE_URL}/getRightAndCount`,
		type: 'post',
		response: config => {
			// 源危险等级分布
			let levelList = [{
					name: "Ⅰ类",
					itemStyle: {
						color: "#d0021b"
					}
				},
				{
					name: "Ⅱ类",
					itemStyle: {
						color: "#ff4747"
					}
				}, {
					name: "Ⅲ类",
					itemStyle: {
						color: "#f8780e"
					}
				},
				{
					name: "Ⅳ类",
					itemStyle: {
						color: "#fac14b"
					}
				},
				{
					name: "Ⅴ类",
					itemStyle: {
						color: "#fff29a"
					}
				}
			]

			const data = Mock.mock({
				"countData|3": [{
					name: "@cword(1)总数",
					count: "@integer(1, 1000)"
				}],
				levelList: levelList.map(v => {
					v.id = "@guid"
					v.value = "@natural(1,100)"
					return v
				}),
				// 行业top5
				"dataList|5": [{
					'name|1': ["科研用源", "测厚仪", "探伤机", "医用源", "XXX源"],
					value: "@natural(1,100)",
					percent: "",
					color: "@hex"
				}],
				"safetyList|5": [{
					'name|1': ["医用源1", "医用源2", "医用源3", "医用源4", "医用源1"],
					'number|1-100': 100
				}]

			})
			// 行业top5处理
			data.dataList = data.dataList.map(v => {
				const total = data.dataList.reduce((prev, next) => prev + next.value, 0)
				v.percent = parseFloat(v.value / total).toFixed(2) * 100
				return v
			})
			data.dataList.sort((a, b) => b.value - a.value)
			// 核安全top5处理
			data.safetyList.sort((a, b) => b.value - a.value)
			return {
				code: 200,
				msg: '',
				data: data
			}
		}
	},
	/**
	 * qiu 异常和区域异常情况
	 */
	{
		url: `${BASE_URL}/getAbnormalAndareaAbnormal`,
		type: 'post',
		response: config => {
			const data = Mock.mock({
				abnormalData: {
					abnormalNum: 10, // 异常总数
					handleAbnormalNum: 2, // 未处理
					noHandleAbnormaNum: 8, // 未处理
				},
				seriesData: {
					"seriesData|6": [{
						'value|1-10': 3,
						legendname: "项目@increment(1)",
						name: "项目@increment(1)",
						itemStyle: {
							'color|1': ["#fca223", '#921140', '#bb0505', '#fc2a2a', '#fca223']
						}
					}],
					abnormalTotal: 0
				}
			})
			data.seriesData.abnormalTotal = data.seriesData.seriesData.reduce((prev, next) => prev + next.value, 0)
			return {
				code: 200,
				msg: '',
				data: data
			}
		}
	},
	// /**
	//  * qiuliang 行业top5
	//  */
	// {
	// 	url: `${BASE_URL}/information/classificationIndustry`,
	// 	type: 'get',
	// 	response: config => {
	// 		let data = Mock.mock({
	// 			"dataList|5": [{
	// 				name: "@cword(1,5)",
	// 				value: "@natural(1,100)",
	// 				percent: "",
	// 				color: "@hex"
	// 			}]
	// 		})
	// 		data.dataList = data.dataList.map(v => {
	// 			const total = data.dataList.reduce((prev, next) => prev + next.value, 0)
	// 			v.percent = parseFloat(v.value / total).toFixed(2) * 100
	// 			return v
	// 		})
	//         data.dataList.sort((a,b) => b.value - a.value)
	// 		return {
	// 			code: 200,
	// 			msg: '',
	// 			data: data
	// 		}
	// 	}
	// },
	// /**
	//  * qiuliang 核安全top5
	//  */
	// {
	// 	url: `${BASE_URL}/information/nuclearSafety`,
	// 	type: 'get',
	// 	response: config => {
	// 		let data = Mock.mock({
	// 			"safetyList|5": [{
	// 				name: "@cword(1,5)",
	// 				number: "@natural(1,100)"
	// 			}]
	// 		})
	//         data.safetyList.sort((a,b) => b.number - a.number)
	// 		return {
	// 			code: 200,
	// 			msg: '',
	// 			data: data
	// 		}
	// 	}
	// },
]
